* ======================================
* ------- Split Immigrants, party ------
* ======================================


	use $dta\EstimationSample.dta, clear

	* Keep only immigrants
	keep if Voter_immigrant == 1
	

* Estimate models
* ===============	
	
	egen idbsu = group(Voter_id Voter_bsu)
	gen period = 1*(year == 2019)
	xtset idbsu period
	estimates clear	

	
	foreach net in Fam1 Fam2{		
		preserve
	
		gen Any = 1*(`net'Any == 1)
		foreach p in rodt sv a sp mdg krf v h frp{
			gen Same_`p' = 1*(`net'Same == 1 & `net'Pol_party == "`p'")	
		}

		eststo NatImm_`net'_`var': xtreg Voter_turnout Any Same_* i.period, ///
			i(idbsu) fe cluster(Voter_bsu)
		restore
		
		* Extract coeffs
		matrix est`net' = r(table)
		matrix est`net' = est`net''
		svmat2 est`net', rnames(party_`net')
		rename est`net'1 b_`net'
		rename est`net'5 cil_`net'
		rename est`net'6 ciu_`net'			
	}

	keep b_* ci?_* party_Fam1 
	keep if _n > 1 & _n <= 10
	gen party_loc = substr(party_Fam1,6,.)
	

* Merge survey
* ============	

	merge 1:1 party_loc using $dta/SurveyAttitudes.dta, keep(master matched) nogen

	
* Construct plot
* ==============
		
	gen party = ""
	replace party = "Red" if party_loc == "rodt"
	replace party = "Soc. Left"  if party_loc == "sv"
	replace party = "Labour"  if party_loc == "a"
	replace party = "Centre" if party_loc == "sp"
	replace party = "Christian Dem." if party_loc == "krf"
	replace party = "Liberal" if party_loc == "v"
	replace party = "Conservative"  if party_loc == "h"
	replace party = "Progress"  if party_loc == "frp"
	replace party = "Green" if party_loc == "mdg"

	gen pos = 9
	replace pos = 3 if party == "Soc. Left"
	replace pos = 3 if party == "Labour"	
	replace pos = 8 if party == "Liberal"	
	replace pos = 8 if party == "Centre"	
						
	twoway 	(rspike cil_Fam1 ciu_Fam1 partyAttitudes) ///
			(scatter b_Fam1 partyAttitudes if partyBloc == "Left", ///
				msym(O) mfcol(white) mlcol(gs2) msize(medium) ///
				mlabel(party) mlabvpos(pos) mlabsize(vsmall)) ///
			(scatter b_Fam1 partyAttitudes if partyBloc == "Right", ///
				msym(O) mfcol(gs8) mlcol(gs2) msize(medium) ///
				mlabel(party) mlabvpos(pos) mlabsize(vsmall)), ///
			ytitle(Coefficient estimate, size(medsmall)) ///
			ylab(-0.4(0.2)1, format(%9.1f) ) ///
			xlab(0(0.2)1, format(%9.1f) ) ///
			xtitle("Should participate more" "(fraction agreeing)", size(medsmall)) ///
			title("Family (close)", size(medium)) ///
			yline(0, lpattern(solid) lcol(cranberry)) ///
			legend(pos(6) row(1) order(2 3) label(2 "Left bloc") label(3 "Right bloc")) ///
			scheme(plotplain) name(Fam1, replace)
			
	twoway 	(rspike cil_Fam2 ciu_Fam2 partyAttitudes) ///
			(scatter b_Fam2 partyAttitudes if partyBloc == "Left", ///
				msym(O) mfcol(white) mlcol(gs2) msize(medium) ///
				mlabel(party) mlabvpos(pos) mlabsize(vsmall)) ///
			(scatter b_Fam2 partyAttitudes if partyBloc == "Right", ///
				msym(O) mfcol(gs8) mlcol(gs2) msize(medium) ///
				mlabel(party) mlabvpos(pos) mlabsize(vsmall)), ///
			ytitle(Coefficient estimate, size(medsmall)) ///
			ylab(-0.4(0.2)1, format(%9.1f) ) ///
			xlab(0(0.2)1, format(%9.1f) ) ///
			xtitle("Should participate more" "(fraction agreeing)", size(medsmall)) ///
			title("Family (extended)", size(medium)) ///	
			yline(0, lpattern(solid) lcol(cranberry)) ///
			legend(pos(6) row(1) order(2 3) label(2 "Left bloc") label(3 "Right bloc")) ///
			scheme(plotplain) name(Fam2, replace)
			
			
	grc1leg Fam1 Fam2, scheme(plotplain) ycommon
	graph export $figs/ImmigrantsFamilyParty.pdf, replace